#ifndef STREAM_H
#define STREAM_H

#include "common.h"

#define OUTSTREAM     stream::get_os()
#define PRINTOUT      stream::print()


class stream {
public:
    static stream &instance() { static stream sinstance; return sinstance; }

    static std::ostream &get_os();
    static VOID print();

    static FunctionSuccesFailure system_message(const std::string &module, const std::string &output);
    static FunctionSuccesFailure error_message(const std::string &module, const std::string &output);
    
private:
    stream() {}  
    stream(const stream&);
    stream &operator=(const stream&); 
    
    static std::ostream &os;
    static std::ostream &oerr;
    static std::istream &is;
    static const UINT_PTR ostreamMutex;
    static const UINT_PTR ostreamSystemMutex;
    static const UINT_PTR ostreamDesynchroMutex;

    static BOOL desynchroPending;
    static const UINT ostreamWaitMsTimeout = 100;

    static FunctionSuccesFailure output_message(const std::string &module, const std::string &output);
    static FunctionSuccesFailure error_output_message(const std::string &module, const std::string &err_output);
    static VOID desynchronized_threads_handler(UINT_PTR mutex_blocked, UINT_PTR mutex_current_owner);
    static VOID desynchronization_source_handler(UINT_PTR mutex_current_owner);
};


#endif
